package com.bupt.vueblog.service.impl;

import com.bupt.vueblog.dao.RelationDAO;
import com.bupt.vueblog.domain.entity.Relation;
import com.bupt.vueblog.service.RelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 谭继好
 * @Description
 * @date 2024-04-10 08:19
 */
@Service
public class RelationServiceImpl implements RelationService {

    @Autowired
    private RelationDAO relationDAO;

    @Override
    public void insert(Relation relation) {
        relationDAO.insert(relation);
    }

    @Override
    public void delete(Relation relation) {
        relationDAO.delete(relation);
    }

    @Override
    // 删除评论下所有点赞关系
    public void deleteComment(Integer commentId) {
        relationDAO.deleteComment(commentId);
    }

    @Override
    @Transactional
    // 同时删除用户对文章和评论的点赞关系
    public void deleteArticleAndComment(Integer userId) {
        relationDAO.deleteArticleUser(userId);
        relationDAO.deleteCommentUser(userId);
    }

    @Override
    // 删除文章所有点赞关系
    public void deleteArticle(Integer articleId) {
        relationDAO.deleteArticle(articleId);
    }

}
